<template>
  <div>
    <div class="px-20">
      <UploadImage />
    </div>
    <Loading
      type="spinner"
      v-if="loading"
      color="#0094ff"
      class="absolute top-1/2 left-1/2"
    />
    <div v-if="hasScore" class="text-center mt-40">
      相似度： {{ score || '?' }} 分
    </div>
  </div>
</template>

<script>
import UploadImage from '@/components/UploadImage/index.vue'
import { getLocalStore } from '@/config/global'
import { fetchLivenessResult } from '@/api'
import { Loading } from 'vant'
export default {
  name: 'CreditPhoto',
  components: { Loading, UploadImage },
  data() {
    return {
      score: 0,
      hasScore: false,
      loading: false
    }
  },
  created() {},
  mounted() {
    this.hasScore = !!this.$route.query.hasScore
    this.hasScore && this.fetchResult()
  },
  methods: {
    fetchResult() {
      const token = getLocalStore('advanceToken', true)
      this.loading = true
      fetchLivenessResult(token)
        .then(res => {
          this.loading = false
          this.score = res
        })
        .catch(() => {
          this.loading = false
        })
    }
  }
}
</script>

<style lang="less" scoped></style>
